# $NetBSD$

DISTNAME=	adguardhome-0.107.28
CATEGORIES=	net
MASTER_SITES=	${MASTER_SITE_GITHUB:=AdguardTeam/}
GITHUB_TAG=	v${PKGVERSION_NOREV}
GITHUB_PROJECT=	AdGuardHome

FRONTEND=	${PKGNAME_NOREV}-frontend.tar.gz
SITES.adguardhome-0.107.28-frontend.tar.gz= https://bbartlomiej-public.s3.eu-central-1.amazonaws.com/adguardhome/
DISTFILES=	${DEFAULT_DISTFILES} ${FRONTEND}

MAINTAINER=	bbartlomiej@gmail.com
HOMEPAGE=	https://github.com/AdguardTeam/AdGuardHome/
COMMENT=	Network-wide ads- and trackers-blocking DNS server
LICENSE=	gnu-gpl-v3

CHECK_RELRO_SKIP+=	sbin/adguardhome

# This software requires some frontend assets which are generated by npm and
# nodejs packages. To build those assets, please uncomment below variables and
# run generate-frontend target. Next the resulting archive has to be uploaded
# to distfile location on pkgsrc distfile server. This has to be done once per
# package version by pkgsrc maintainer and only when those assets change. The
# reason is if npm commands are run during the build doznes of npm packages
# would get downloaded bypassing pkgsrc fetch model.
#TOOL_DEPENDS+=	npm>=6.14:../../lang/npm
#TOOL_DEPENDS+=	nodejs>=10.16:../../lang/nodejs

USE_TOOLS+=	tar

OWN_DIRS+=	libdata/adguardhome

.include "go-modules.mk"

INSTALLATION_DIRS+=	sbin libdata/adguardhome
PKG_SYSCONFSUBDIR=	adguardhome
RCD_SCRIPTS+=		adguardhome

do-build:
	${RUN} cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${GO} build --ldflags="-s -w -X github.com/AdguardTeam/AdGuardHome/internal/version.version=v${PKGVERSION_NOREV} -X github.com/AdGuardTeam/AdGuardHome/internal/version..channel=release -X github.com/AdGuardTeam/AdGuardHome/internal/version..goarm=${GOARM}"

do-install:
	${INSTALL_PROGRAM} ${WRKSRC}/AdGuardHome ${DESTDIR}${PREFIX}/sbin/adguardhome

.PHONY: generate-frontend
generate-frontend:
	cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} npm --prefix client ci
	cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} npm --prefix client run build-prod
	cd ${WRKDIR} && ${TAR} -zcf ${WRKDIR}/${PKGNAME_NOREV}-frontend.tar.gz AdGuardHome-${PKGVERSION_NOREV}/build
	@${ECHO} "Now upload ${WRKDIR}/${PKGNAME_NOREV}-frontend.tar.gz to LOCAL_PORTS"

.include "../../mk/bsd.prefs.mk"
.include "../../lang/go/go-module.mk"
.include "../../mk/bsd.pkg.mk"
